<extend name="Public/base" />

<block name="body">
	<div class="am-cf am-u-md-12 header-title">
		<h2>新增模型</h2>
	</div>

	<!-- 标签页导航 -->
	<div class="am-cf am-u-md-12">
		<!-- 表单 -->
		<form id="form" action="{:U('update')}" method="post" class="am-form am-form-horizontal doc-modal-form">
			<!-- 基础 -->
			<div class="am-form-group">
				<label class="am-u-sm-2 am-form-label">模型标识</label>
				<div class="am-u-sm-10">
					<input type="text" class="am-form-field " name="name" value="">
					<span class="am-form-help">（请输入文档模型标识）</span>
				</div>
			</div>
			<div class="am-form-group">
				<label class="am-u-sm-2 am-form-label">模型名称</label>
				<div class="am-u-sm-10">
					<input type="text" class="am-form-field " name="title" value="">
					<span class="am-form-help">（请输入模型的名称）</span>
				</div>
			</div>
			<div class="am-form-group">
				<label class="am-u-sm-2 am-form-label">模型类型</label>
				<div class="am-u-sm-10">
					<select name="extend" class="am-form-field">
						<option value="0">独立模型</option>
						<option value="1">文档模型</option>
					</select>
					<span class="am-form-help">（目前只支持独立模型和文档模型）</span>
				</div>
			</div>
			<div class="am-form-group">
				<label class="am-u-sm-2 am-form-label">引擎类型</label>
				<div class="am-u-sm-10">
					<select name="engine_type" class="am-form-field">
						<option value="MyISAM">MyISAM</option>
						<option value="InnoDB">InnoDB</option>
                        <option value="MEMORY">MEMORY</option>
                        <option value="BLACKHOLE">BLACKHOLE</option>
                        <option value="MRG_MYISAM">MRG_MYISAM</option>
                        <option value="ARCHIVE">ARCHIVE</option>
					</select>
					<span class="am-form-help"></span>
				</div>
			</div>
			<div class="am-form-group">
				<label class="am-u-sm-2 am-form-label">是否需要主键</label>
				<div class="am-u-sm-10">
					<select name="need_pk" class="am-form-field">
						<option value="1" selected="selected">是</option>
						<option value="0">否</option>
					</select>
					<span class="am-form-help">（选“是”则会新建默认的id字段作为主键）</span>
				</div>
			</div>

			<!-- 按钮 -->
			<div class="am-form-group">
				<label class="am-u-sm-2 am-form-label"></label>
				<div class="am-u-sm-10 edit_sort_btn">
					<button class="am-btn am-btn-primary submit-btn ajax-post no-refresh" type="submit" target-form="am-form-horizontal">确 定</button>
					<button class="am-btn am-btn-default btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
				</div>
			</div>
		</form>
	</div>
</block>
<block name="script">
<script type="text/javascript" src="__PUBLIC__/js/jquery.dragsort-0.5.1.min.js"></script>
<script type="text/javascript" charset="utf-8">
    //导航高亮
    highlight_subnav('{:U('Model/index')}');

    $(function(){
    	showTab();
    })
//拖曳插件初始化
$(function(){
	$(".dragsort").dragsort({
	     dragSelector:'li',
	     placeHolderTemplate: '<li class="draging-place">&nbsp;</li>',
	     dragBetween:true,	//允许拖动到任意地方
	     dragEnd:function(){
	     	updateVal();
	     }
	 });

	$('#sortUl li b').click(function(){
		$(this).parent().remove();
		updateVal();
	});

	// 更新排序后的隐藏域的值
	function updateVal() {
		var sortVal = [];
		var i = 1;
		var val = '';
	   	$('#base li').each(function(){
	   		sortVal[i++] = $(this).find('em').text();
	   	});
	   	i = -1;
	   	$('#extend li').each(function(){
	   		sortVal[i--] = $(this).find('em').text();
	   	});
	   	//将排序数组拼接成json格式字符串
	   	val += "[";
	   	for (k in sortVal){
	   		val += "\"" + sortVal[k] + "\"" + ":" + k + ",";
	   	}
	   	val = val.substr(0,val.length - 1) + "]";
	    $("input[name='fields']").val(val);
	}
})
</script>
</block>

